
#ifndef RTCHANNELFILE_H
#define RTCHANNELFILE_H

#include "RtHttpInterface.h"
#include "RtTimerWrapper.h"

class CRtHttpUrl;

class /*RT_API_EXPORT*/ CRtChannelFile 
	: public IRtChannel 
	, public CRtReferenceControlSingleThreadTimerDelete
	, public CRtTimerWrapperSink
{
public:
	CRtChannelFile();
	virtual ~CRtChannelFile();

	BOOL Init(CRtHttpUrl *aUrl);
	BOOL Init(const CRtString &aPath);

	// interface IRtReferenceControl
	virtual DWORD AddReference();
	virtual DWORD ReleaseReference();

	// interface IRtChannel
	virtual RtResult AsyncOpen(IRtChannelSink *aSink);
	virtual RtResult GetUrl(CRtHttpUrl *&aUrl);

	// interface IRtTransport
	virtual RtResult OpenWithSink(IRtTransportSink *aSink);
	virtual IRtTransportSink* GetSink();
	virtual RtResult SendData(
		CRtMessageBlock& inData,
		BOOL inSendImmediately = TRUE,
		BOOL inDestroyData = FALSE,
		DataPriority inPriority = DP_MEDIUM, 
		BOOL inNeedAck = TRUE);
	virtual RtResult SetOption(DWORD aCommand, LPVOID aArg);
	virtual RtResult GetOption(DWORD aCommand, LPVOID aArg);
	virtual RtResult Disconnect(RtResult aReason);

	// interface CRtTimerWrapperSink
	virtual void OnTimer(CRtTimerWrapper* aId);

private:
	CRtString m_strFileName;
	FILE *m_pfGet;
	IRtChannelSink *m_pSink;
	CRtTimerWrapper m_TimerReadFile;
	BOOL m_bSync;
};

#endif // !RTCHANNELFILE_H
